<template>
    <div>
        <div>upload</div>
        <el-upload
        class="avatar-uploader"
        action="http://localhost:8080/common"
        :show-file-list="false"
        :on-success="handleAvatarSuccess"
        >
        <img v-if="imageUrl" :src="imageUrl" class="avatar">
        <i v-else class="el-icon-plus avatar-uploader-icon"></i>
        </el-upload>
        <el-button type="primary" @click="handleAdd() ">提交</el-button>
    </div>
</template>

<script>
import { goPicture } from '@/api/user'
export default {
  name: 'uploadIndex',
  data () {
    return {
      imageUrl: null
    }
  },
  methods: {
    async handleAvatarSuccess (res, file) {
      // 创建一个临时的URL地址，该地址代表了上传文件的内容
      // this.imageUrl = URL.createObjectURL(file.raw)
      this.imageUrl = file.response.data
      console.log(this.imageUrl)
    },
    async handleAdd () {
      const res = await goPicture(this.imageUrl)
      console.log(res)
      console.log(this.imageUrl)
    }
  }
}
</script>

<style>
  .avatar-uploader .el-upload {
    border: 1px dashed #d9d9d9;
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
  }
  .avatar-uploader .el-upload:hover {
    border-color: #409EFF;
  }
  .avatar-uploader-icon {
    font-size: 28px;
    color: #8c939d;
    width: 178px;
    height: 178px;
    line-height: 178px;
    text-align: center;
  }
  .avatar {
    width: 178px;
    height: 178px;
    display: block;
  }
</style>
